//
//  HWTopicDetailView.swift
//  HWanGame
//
//  Created by Apple on 2024/8/23.
//  Copyright © 2024 94Wan. All rights reserved.
//

import UIKit
import Stevia

class HWTopicDetailTopView: UIView {

    private let logoImageView = c_make_ex(UIImageView.self)
        .image("Topic_logo").end()
    private let titleLabel = c_make_ex(UILabel.self)
        .color(.black).font(16.font_semiBold).end()
    private let viewsLabel = c_make_ex(UILabel.self)
        .color("#AEB0B3").font(12.font_medium).end()
    private let backView = c_make_ex(UIView.self)
        .bgColor("#F2F3F5").corner(8*widthScale).end()
    private let contentLabel = c_make_ex(UILabel.self)
        .color("#7B7D80").font(12.font_medium).end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        subviews{
            logoImageView
            titleLabel
            viewsLabel
        }
        
        logoImageView.leading(16*widthScale).top(0).size(22*widthScale)
        titleLabel.leading(16*widthScale).top(0).trailing(16*widthScale)
        viewsLabel.leading(16*widthScale).top(25*widthScale).trailing(16*widthScale)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


//MARK:
class HWTopicDetailCateHeader: UITableViewHeaderFooterView {
    
    private let hotLabel = c_make_ex(UIButton.self)
        .color("#2E3033",state: .selected).color("#47494D")
        .font(14.font_semiBold).alignment(.center).text("最热").end()
    private let hotLineView = c_make_ex(UIView.self)
        .bgColor("#2E3033").corner(0.7).end()
    private let newLabel = c_make_ex(UIButton.self)
        .color("#2E3033",state: .selected).color("#47494D")
        .font(14.font_semiBold).alignment(.center).text("最新").end()
    private let newLineView = c_make_ex(UIView.self)
        .bgColor("#2E3033").corner(0.7).end()
    
    var updateCateData: ((_ cateID: Int) -> Void)?
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.subviews{
            hotLabel
            hotLineView
            newLabel
            newLineView
        }
        
        
        hotLabel.leading(12*widthScale).top(0).height(38*widthScale).width(44*widthScale)
        newLabel.leading(56*widthScale).top(0).height(38*widthScale).width(44*widthScale)
        hotLineView.height(2*widthScale).width(28*widthScale).top(28*widthScale)
        hotLineView.CenterX == hotLabel.CenterX
        newLineView.height(2*widthScale).width(28*widthScale).top(28*widthScale)
        newLineView.CenterX == newLabel.CenterX
        
        hotLabel.isSelected = true
        hotLineView.isHidden = false
        newLabel.isSelected = false
        newLineView.isHidden = true
        
        hotLabel.addTarget(self, action: #selector(clickHotButton), for: .touchUpInside)
        newLabel.addTarget(self, action: #selector(clickNewButton), for: .touchUpInside)
    }
    
    @objc private func clickHotButton(){
        
        if !hotLabel.isSelected {
            
            hotLabel.isSelected = true
            hotLineView.isHidden = false
            newLabel.isSelected = false
            newLineView.isHidden = true
            
            updateCateData?(1)
        }
    }
    
    @objc private func clickNewButton(){
        
        if !newLabel.isSelected {
            
            newLabel.isSelected = true
            newLineView.isHidden = false
            hotLabel.isSelected = false
            hotLineView.isHidden = true
            
            updateCateData?(1)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
